namespace FreeWorkflow.DataAccess.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class FWFInitalDatabase : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "fwf.Roles",
                c => new
                    {
                        RoleId = c.String(nullable: false, maxLength: 128),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.RoleId);
            
            CreateTable(
                "fwf.Tasks",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Title = c.String(),
                        Outcome = c.String(),
                        DateCreated = c.DateTime(nullable: false),
                        DateClosed = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "fwf.Users",
                c => new
                    {
                        UserId = c.String(nullable: false, maxLength: 128),
                        UserName = c.String(nullable: false),
                        PasswordHash = c.String(),
                        SecurityStamp = c.String(),
                    })
                .PrimaryKey(t => t.UserId);
            
            CreateTable(
                "fwf.UserClaim",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ClaimType = c.String(),
                        ClaimValue = c.String(),
                        User_Id = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("fwf.Users", t => t.User_Id, cascadeDelete: true)
                .Index(t => t.User_Id);
            
            CreateTable(
                "fwf.UserLogin",
                c => new
                    {
                        UserId = c.String(nullable: false, maxLength: 128),
                        LoginProvider = c.String(nullable: false, maxLength: 128),
                        ProviderKey = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.UserId, t.LoginProvider, t.ProviderKey })
                .ForeignKey("fwf.Users", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "fwf.UserRoles",
                c => new
                    {
                        UserId = c.String(nullable: false, maxLength: 128),
                        RoleId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.UserId, t.RoleId })
                .ForeignKey("fwf.Roles", t => t.RoleId, cascadeDelete: true)
                .ForeignKey("fwf.Users", t => t.UserId, cascadeDelete: true)
                .Index(t => t.RoleId)
                .Index(t => t.UserId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("fwf.UserRoles", "UserId", "fwf.Users");
            DropForeignKey("fwf.UserRoles", "RoleId", "fwf.Roles");
            DropForeignKey("fwf.UserLogin", "UserId", "fwf.Users");
            DropForeignKey("fwf.UserClaim", "User_Id", "fwf.Users");
            DropIndex("fwf.UserRoles", new[] { "UserId" });
            DropIndex("fwf.UserRoles", new[] { "RoleId" });
            DropIndex("fwf.UserLogin", new[] { "UserId" });
            DropIndex("fwf.UserClaim", new[] { "User_Id" });
            DropTable("fwf.UserRoles");
            DropTable("fwf.UserLogin");
            DropTable("fwf.UserClaim");
            DropTable("fwf.Users");
            DropTable("fwf.Tasks");
            DropTable("fwf.Roles");
        }
    }
}
